<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #canvas {
            border: 1px solid #333;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="200" height="200"></canvas>
    <script>
        /* 1、画布 */
        var canvas = document.getElementById("canvas");
        /* 2、context */
        var ctx = canvas.getContext("2d");
        let increase = true;
        let radius = 50;
        /*
        50~80 在50到80之间，不断变化
        <50   true  radius ++
        >80   false radius --
         */
        function draw() {
            /* 清空画布 */
            ctx.clearRect(0, 0, canvas.width, canvas.height)
            /* 圆 */
            ctx.beginPath()
            ctx.arc(100, 100, radius, 0, Math.PI * 2)
            ctx.closePath();
            ctx.fillStyle = "#652e8044"
            ctx.fill();
            ctx.stroke()
            if (radius > 80) {
                increase = false;
            } else if (radius < 50) {
                increase = true;
            }
            if (increase) {
                radius++;
            } else {
                radius--;
            }
            setTimeout(draw, 20)
        }
        draw()
        // setInterval(draw, 20)
    </script>
</body>

</html>